<template>
  <div>
    <!--    直接从this.$store.state中拿数据-->
    <h1>当前sum的值为{{ sum }}</h1>
    <h2>当前sum的值放大十倍为{{ bigsum }}</h2>
    <h2>我在 {{ school }} 学习 {{ subject }} </h2>
    <h2>Person组件的总人数:{{ personList.length }}</h2>
    <select v-model.number="n">
      <option value="1">1</option>
      <option value="2">2</option>
      <option value="3">3</option>
    </select>
    <button @click="incrementNum(n)">+</button>
    <button @click="decrementNum(n)">-</button>
    <button @click="incrementOdd(n)">当前和为奇数再加</button>
    <button @click="incrementWait(n)">等一等再加</button>
  </div>
</template>

<script>
//用于一键生成state和getter中所需要配置到组件中的数据
import {mapState} from "vuex";
import {mapGetters} from "vuex";
import {mapActions} from "vuex";
import {mapMutations} from "vuex";

export default {
  name: 'MyCount',
  data() {
    return {
      n: 1
    }
  },
  methods: {
    //辅助函数生成对应方法
    ...mapActions('countAbout', {incrementOdd: 'jiaOdd', incrementWait: 'jiaWait'}),//调用dispatch
    ...mapMutations('countAbout', {incrementNum: 'JIA', decrementNum: 'JIAN'}),//调用commit
  },
  mounted() {
    console.log(this)
  },
  computed: {
    //将二者mapState生成计算属性,从state中读取数据(对象写法)   注意mapState中不支持执行表达式
    //对象中的数据映射到数组中的数据
    ...mapState('countAbout', ['sum', 'school', 'subject']),
    ...mapState('presonAbout', ['personList']),
    //展开运算符
    ...mapGetters('countAbout', ['bigsum'])

    //当计算属性的属性名和state/getters中属性名一样的时候,我们可以使用数组进行简写
  },

}
</script>


<style scoped>

</style>